package nyist.media.entity.admin;

import lombok.Getter;
import lombok.Setter;
import nyist.media.entity.BaseEntity;
import nyist.media.entity.OrderBaseEntity;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * 菜单权限
 *
 * @author dcf
 */
@Getter
@Setter
@Entity
@Table(name = "m_p_menu_auth")
public class MenuAuth extends OrderBaseEntity {
    private static final long serialVersionUID = 7752890655145755993L;

    public enum Type {

        /**
         * 菜单
         */
        MENU,

        /**
         * 目录
         */
        CATALOG
    }

    /**
     * 菜单名	varchar(20)	非空
     */
    @Column(nullable = false, length = 20)
    private String name;

    /**
     * 上级菜单	bigint	外键
     */
    @ManyToOne(fetch = FetchType.LAZY)
    private MenuAuth parent;

    /**
     * 是否启用	bit(1)	非空
     */
    @Column(nullable = false, columnDefinition = "bit(1)")
    private boolean enabled;

    /**
     * 层级	int	非空
     */
    @Column(nullable = false)
    private int grade;

    /**
     * 链接地址
     */
    private String href;

    /**
     * 图标
     */
    private String icon;

    /**
     * 是否在菜单栏显示
     */
    @Column(nullable = false)
    private boolean showMenu;

    /**
     * 类型	int	非空，类型有菜单和菜单项两种
     */
    @Column(nullable = false, columnDefinition = "int COMMENT '类型有菜单和菜单项两种'")
    private Type type;

    /**
     * 树路径	varchar(255)	非空
     */
    @Column(nullable = false)
    private String treePath;

    /**
     * 权限  varchar(50)
     */
    @Column(length = 50)
    private String authority;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
    private Set<MenuAuth> children = new HashSet<>();
}
